/**
 * App() 函数
 *
 * 用来注册一个小程序。接受一个 object 参数，其指定小程序的生命周期函数等。
 *
 * @param onLaunch // 当小程序初始化完成时，会触发 onLaunch（全局只触发一次）
 * @param onShow   // 当小程序启动，或从后台进入前台显示，会触发 onShow
 * @param onHide   // 当小程序从前台进入后台，会触发 onHide
 * @param getUserInfo // 获取用户信息
 *
 * @author marsliang <marsliang@tencent.com>
 * @date   2016‎-11-‎14 ‎20:07:04
 * @update 2016-11-17
 */

App({
    onLaunch: function () {

    },
    onLoad: function () {

    },
    onShow: function () {
        wx.setStorage({
            key: 'flag',
            data: 0
        })
    },
    onHide: function () {

    },
    onUnload: function () {

    },
    getUserInfo: function (cb) {
        var that = this
        if (this.globalData.userInfo) {
            typeof cb == "function" && cb(this.globalData.userInfo)
        } else {
            //调用登录接口
            wx.login({
                success: function (r) {
                    // 获取用户信息
                    wx.getUserInfo({
                        success: function (res) {
                            that.globalData.userInfo = res.userInfo
                            typeof cb == "function" && cb(that.globalData.userInfo)
                            wx.setStorageSync('nickName', res.userInfo.nickName)
                            wx.setStorageSync('avatarUrl', res.userInfo.avatarUrl)
                        }
                    });

                    // 获取用户openid
                    wx.request({
                        url: 'https://xcx.ahdhst.cn/tp/public/index.php/Index/sign/userlogin',
                        data: {
                            "key": "0024000004800000940000000602000000240000525341310004000001000100F533D2223B417EC1D3B5EA64E57E9736B862805CE6371AC24CAED78B7A86F1E1DFC019A78A1B8D8916C35D11856AFA3128B265793FAF8A82EBD93190FF4721C8888207C926C8DD58FD87B2EF56EF24AC1AC07090C5CC518EBEE053B9E0D384C8A0AAD4EAD489F8F46D2C6458C584C9457AA9AD62CE48B88C8EFD15B63A102BB2",
                            'js_code': r.code
                        },
                        method: 'GET',
                        success: function (res) {
                            wx.setStorageSync('openId', res.data.openid)
                        }
                    })
                }
            })
        }
    },

    globalData: {
        userInfo: null,
        openId: '',
        projectArr:{},
        data:{
            info:"",
            costRemark:"",
            jdRemark:"",
            jdParticipant:"",
            carTarget:"",
            goodsRemark:"",
            otherRemark:"",
        },
        "key": "0024000004800000940000000602000000240000525341310004000001000100F533D2223B417EC1D3B5EA64E57E9736B862805CE6371AC24CAED78B7A86F1E1DFC019A78A1B8D8916C35D11856AFA3128B265793FAF8A82EBD93190FF4721C8888207C926C8DD58FD87B2EF56EF24AC1AC07090C5CC518EBEE053B9E0D384C8A0AAD4EAD489F8F46D2C6458C584C9457AA9AD62CE48B88C8EFD15B63A102BB2",
        SERVER_URL:'https://xcx.ahdhst.cn/tp/public/index.php/Index'
    }
})